import requests
import json
import tests.Assertion.token_replace
from itertools import islice

# import os
from collections.abc import Sequence,MutableMapping


def get_paths(source):
    paths = []
    if isinstance(source, MutableMapping):
        for k, v in source.items():
            paths.append([[k]])
            paths += [[[k]] + x for x in get_paths(v)]
    elif isinstance(source, Sequence) and not isinstance(source, str):
        for i, v in enumerate(source):
            paths.append([[i]])
            paths += [[[i]] + x for x in get_paths(v)]
    return paths
def json_path_value(jsondict,path):
    try:
        num=1
        pahts = path.split(",")
        mydict={}
        for p in pahts:
            if num==1:
                mydict = jsondict[p+""]
                num=num+1
            else:
                mydict = mydict[p+""]
                num=num+1
        return mydict
    except Exception as e:
        print("get value from path failure and the exception is "+str(e))
        return None

def get_url(url,headers):
    '''
    :param url: get请求的url
    :param headers: 请求的headers
    :return: 返回请求的处理过的json
    '''
    geturl=url
    hd =headers
    List = requests.get(geturl, headers=headers)
    data_json = json.loads(List.text)
    return data_json
def post_url(url,headers,data):
    print(url,headers,data)
    posturl=url
    headers = headers
    data = data
    List = requests.post(posturl, headers=headers,json=data)
    print ("ListListList",(List))
    data_json = json.loads(List.text)
    return data_json
def get_url_token(url,headers):
    '''
    :param url: get请求的url
    :param headers: 请求的headers
    :return: 返回token
    '''
    geturl=url
    hd =headers
    List = requests.get(geturl, headers=headers)
    token = List.json()['token']
    return token
def post_url_token(url,headers,data):
    posturl=url
    headers = headers
    data = data
    List = requests.post(posturl, headers=headers,json=data)
    token = List.json()['token']
    return token
def get_urljson(url,headers):
    posturl=url
    headers = headers
    # print(headers)
    List = requests.post(posturl, headers=headers)
    # print(List)
    data_json_data = List.json()
    return data_json_data

def post_urljson(url,headers,data):
    posturl=url
    headers = headers
    data = data
    List = requests.post(posturl, headers=headers,json=data)
    data_json_data = List.json()
    return data_json_data


def File_Header(fyfilename):
    pyfile = "Test_"+fyfilename + ".py"
    test_case = open(pyfile, 'a+', encoding='utf-8')
    classname = "class Test_"+fyfilename+":"
    test_case.write('import os' + "\n" + 'import requests' + '\n' + 'import json'+"\n"+'import allure'+'\n'+'import pytest'+'\nimport test.token_replace'+'\n'+'import test.Assertion_Generation_Tool'+'\n'+" "+"\n"+classname)
    test_case.close()

def get_listdata(datalist):
    listdata = []
    for a in range(0, len(datalist)):
        c = ''
        for b in range(0, len(datalist[a])):
            c += str(datalist[a][b])
            listdata.append(c)
    return listdata

def listdata(datalist):
    listdata = []
    for a in range(0, len(datalist)):
        c = ''
        for b in range(0, len(datalist[a])):
            c += str(datalist[a][b])
            listdata.append("\""+c+"\"")
    return listdata
def Write_list_data(listdata):
    ListData = listdata
    for yu in range(0, len(ListData)):
        for ya in range(0, len(ListData[yu])):

            try:
                if type(ListData[yu][ya][0]) == int or type(ListData[yu][ya][0]) == float:
                    ListData[yu][ya] = str(ListData[yu][ya][0]).split(',')
            except ValueError as e:
                print()
    return ListData

def Generate_py_file(url,headers,casename,getorpost,data,allureAnnotation,fyfilename,token_inherit,token_inherit_data,executions):

    pyfile ="Test_"+fyfilename+".py"
    token_file = "Test_" + fyfilename + ".txt"
    Interface_file = "Test_jk" + fyfilename + ".txt"
    test_case = open(pyfile, 'a+', encoding='utf-8')
    tokendata = open(token_file, 'a+', encoding='utf-8')
    Interfacedata = open(Interface_file,'a+', encoding='utf-8')
    case1 = '      pytest.assume(result'
    classname = "   def test_"+ casename+"(self):"
    # test_case.write('import os'+"\n"+'import requests'+'\n'+'import json')


    for d in range(0,len(allureAnnotation)):
        # print(allureAnnotation[d])
        if allureAnnotation[d] !='':
            test_case.write('\n   '+allureAnnotation[d])
    test_case.write('\n'+classname+"\n")

    # if executions in token_inherit_data:
    print(executions,"<==============>",token_inherit_data)
    test_case.write("      global "+casename+"_token"+'\n')
    if getorpost == "GET":
        if token_inherit == "":
            data_json = get_url(url=url, headers=headers)
            datajson = get_url(url=url, headers=headers)
            token = get_url_token(url=url, headers=headers)
        else:
            with open(token_file) as myfile:
                head = list(islice(myfile, int(token_inherit)))
            headers = tests.token_replace.getValues().replace_target_Value(key='token', dic=headers,
                                                                           changeData=''.join(head[0]).strip('\n'))
            data_json = get_url(url=url, headers=headers)
            datajson = get_url(url=url, headers=headers)
            token=get_url_token(url=url, headers=headers)

        tokendata.write(str(token)+"\n")
        # url = url, headers = headers, data = data
        test_case.write('\n' + "      url='" + str(url) + "'" + '\n' + '      header=' + str(headers))
        if token_inherit != "":
            with open(Interface_file) as myfile:
                interfacename = list(islice(myfile, int(token_inherit)))
            test_case.write(
            "      header = token_replace.getValues().replace_target_Value(key='token', dic=header,changeData=" + ''.join(
                interfacename[0]).strip('\n') + "_token)")
        test_case.write(
                    '\n' + "      r = requests.get(url,headers=header)" + '\n' + "      result = r.json()" + '\n')
    if getorpost == "POST":
        if token_inherit == "":
            data_json = post_url(url=url, headers=headers, data=data)
            datajson = post_urljson(url=url, headers=headers, data=data)
            token=post_url_token(url=url, headers=headers, data=data)
            # paths = get_paths(data_json)
        else:
            with open(token_file) as myfile:
                head = list(islice(myfile, int(token_inherit)))
            headers = tests.token_replace.getValues().replace_target_Value(key='token', dic=headers, changeData=''.join(head[0]).strip('\n'))

            data_json = post_url(url=url, headers=headers, data=data)
            datajson = post_urljson(url=url, headers=headers, data=data)
            token = post_url_token(url=url, headers=headers, data=data)
        tokendata.write(str(token)+'\n')
        Interfacedata.write(str(casename)+'\n')

        test_case.write('\n' + "      url='" + str(url) + "'" + '\n' + '      header=' + str(
                        headers) + '\n      data=' + str(data)+'\n')
        if token_inherit != "":
            with open(Interface_file) as myfile:
                interfacename = list(islice(myfile, int(token_inherit)))
            test_case.write(
            "      header = token_replace.getValues().replace_target_Value(key='token', dic=header,changeData=" + ''.join(
                interfacename[0]).strip('\n') + "_token)")
        test_case.write(
                        '\n' + "      r = requests.post(url,headers=header,json=data)" + '\n' + "      result = r.json()" + '\n')
    paths = get_paths(data_json)
    test_case.write("      "+casename+"_token =result['token']" +'\n')
    test_case.write("      JsonTree = " + str(Write_list_data(paths)) + '\n')
        # except ValueError as e:
        # print("无cookie继承")
    # else:
    #     print(token_inherit)
    #     if getorpost == "GET":
    #         data_json = get_url(url=url, headers=headers)
    #         token.append(get_url_token(url=url, headers=headers))
    #         url = url, headers = headers, data = data
    #         test_case.write('\n' + "      url='" + str(url) + "'" + '\n' + '      header=' + str(headers))
    #         test_case.write(
    #             '\n' + "      r = requests.get(url,headers=header)" + '\n' + "      result = r.json()" + '\n')
    #         # paths = get_paths(data_json)
    #
    #     if getorpost == "POST":
    #         data_json = post_url(url=url, headers=headers, data=data)
    #         datajson = post_urljson(url=url, headers=headers, data=data)
    #         token.append(post_url_token(url=url, headers=headers, data=data))
    #         test_case.write(
    #             '\n' + "      url='" + str(url) + "'" + '\n' + '      header=' + str(headers) + '\n      data=' + str(
    #                 data))
    #         test_case.write(
    #             '\n' + "      r = requests.post(url,headers=header,json=data)" + '\n' + "      result = r.json()" + '\n')
    #     paths = get_paths(data_json)

    # test_case.write(''.join('%s' %id for id in paths))
    msg='''
   # 对比现在的json字段与之前jion字段的差距
      datapath = Assertion_Generation_Tool.Write_list_data(Assertion_Generation_Tool.get_paths(result))
      print("之前的json结构字段数量："+str(len(JsonTree)))
      print("执行的json结构字段数量："+str(len(datapath)))
      CorrelationData1 = [x for x in JsonTree if x not in datapath]  #在JsonTree列表中而不在datapath列表中
      CorrelationData2 = [y for y in datapath if y not in JsonTree]  #在datapath列表中而不在JsonTree列表中

    '''
    # test_case.write("      JsonTree = "+str(Write_list_data(paths))+'\n')
    test_case.write(msg)
    paths = get_paths(data_json)
    # print(paths)
    for a in range (0,len(paths)):
        c = ''
        for i in range(0, len(paths[a])):
            c += str(paths[a][i])


        if len(paths[a]) ==1:
            try:
                data1 = int(str(paths[a][0]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data1 = str(paths[a][0]).replace('[', '').replace(']', '').replace("'", "")
            datavalue = str(datajson[data1])
            datavalue1 =datajson[data1]
            # print(type(datavalue),datavalue)
            # print(type(data_json[data1]),data_json[data1])
            # print(type(datajson[data1]),data1,datajson[data1])
            newline = ''
            if type(datavalue1) == int or type(datavalue1) == float:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
            elif type(datavalue1) == str:
                newline = case1 + "" + c + " == \'" + datavalue + "\')"
                test_case.write('\n' + newline)
            elif datavalue1 == 'None':
                newline = case1 + "" + c + " == " + r"None" + ")"
                test_case.write('\n' + newline)
            elif type(datavalue1) == bool:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
            elif type(datavalue) == list:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
            # if type(datavalue1) == int or type(datavalue1) == float:
            #     newline = case1 + "" + c + " == " + datavalue + ")"
            #     test_case.write('\n' + newline)
            # elif type(datavalue1) == str:
            #     newline = case1 + "" + c + " == \'" + datavalue + "\')"
            #     test_case.write('\n' + newline)
            # elif datavalue1 == 'None':
            #     newline = case1 + "" + c + " == " + r"None" + ")"
            #     test_case.write('\n' + newline)
            # # elif type(datavalue1) == bool :
            #     newline = case1 + "" + c + " == " + datavalue + ")"
            #     test_case.write('\n' + newline )
            # elif type(datavalue) == list:
            #     newline = case1 + "" + c + " == " + datavalue + ")"
            #     test_case.write('\n' + newline)
        # if '\'' in datavalue and datavalue != 'None':
        #     # if datavalue == 'False' or datavalue == 'True':
        #     #     newline = case1 + "" + c + " == " + datavalue + ")"
        #     #     test_case.write('\n cccccc' + newline)
        #     # else:
        #     newline = case1 + "" + c + " == " + datavalue + ")"
        #     test_case.write('\n aaaaaa' + newline)
        # elif "\'" not in datavalue:
        #     if datavalue == 'None':
        #         newline = case1 + "" + c + " == " + r"None" + ")"
        #         test_case.write('\n nnnnn' + newline)
        #     else:
        #         newline = case1 + "" + c + " == "  # , datavalue + ")"
        #         try:
        #             newline1 = float(datavalue)
        #             test_case.write('\n bbbbb' + newline)
        #             test_case.write(datavalue)
        #             test_case.write(")")
        #         except ValueError as e:
        #             if datavalue == 'False' or datavalue == 'True':
        #                 newline = case1 + "" + c + " == " + datavalue + ")"
        #                 test_case.write('\n cccccc' + newline)
        #             else:
        #                 test_case.write('\n dddddd' + newline)
        #                 test_case.write("\'" + datavalue + "\'")
        #                 test_case.write(")")
        # elif "\"" in datavalue:
        #     datavalue = datavalue.replace('\"', r'\"')
        #     newline = case1 + "" + c + " == " + "\"" + datavalue + "\")"
        #     print("datavalue" + newline)
        #     test_case.write('\n' + newline)
        # else:
        #     newline = case1 + "" + c + " == " + "\"" + datavalue + "\")"
        #     test_case.write('\n' + newline)
        if len(paths[a])==2:
            try:
                data1 = int(str(paths[a][0]).replace('[', '').replace(']', '').replace("'", ""))

            except ValueError as e:
                data1 = str(paths[a][0]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data2 = int(str(paths[a][1]).replace('[', '').replace(']', '').replace("'", ""))

            except ValueError as e:
                data2 = str(paths[a][1]).replace('[', '').replace(']', '').replace("'", "")
            datavalue = str(data_json[data1][data2])
            datavalue1 = datajson[data1][data2]
            newline = ''
            if type(datavalue1) == int or type(datavalue1) == float:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
            elif type(datavalue1) == str:
                newline = case1 + "" + c + " == \'" + datavalue + "\')"
                test_case.write('\n' + newline)
            elif datavalue1 == 'None':
                newline = case1 + "" + c + " == " + r"None" + ")"
                test_case.write('\n' + newline)
            elif type(datavalue1) == bool:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
            elif type(datavalue) == list:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
        if len(paths[a])==3:
            try:
                data1 = int(str(paths[a][0]).replace('[', '').replace(']', '').replace("'", ""))

            except ValueError as e:
                data1 = str(paths[a][0]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data2 = int(str(paths[a][1]).replace('[', '').replace(']', '').replace("'", ""))

            except ValueError as e:
                data2 = str(paths[a][1]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data3 = int(str(paths[a][2]).replace('[', '').replace(']', '').replace("'", ""))

            except ValueError as e:
                data3 = str(paths[a][2]).replace('[', '').replace(']', '').replace("'", "")
            # print("3层"+str(paths[a])+"====>"+str(data_json[data1][data2][data3]))
            # print(str(paths[a].replace('[', '').replace(']', '')))
            datavalue = str(data_json[data1][data2][data3])
            datavalue1 = datajson[data1][data2][data3]
            newline = ''
            if type(datavalue1) == int or type(datavalue1) == float:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
            elif type(datavalue1) == str:
                newline = case1 + "" + c + " == \'" + datavalue + "\')"
                test_case.write('\n' + newline)
            elif datavalue1 == 'None':
                newline = case1 + "" + c + " == " + r"None" + ")"
                test_case.write('\n' + newline)
            elif type(datavalue1) == bool:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
            elif type(datavalue) == list:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
        if len(paths[a]) == 4:
            try:
                data1 = int(str(paths[a][0]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data1 = str(paths[a][0]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data2 = int(str(paths[a][1]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data2 = str(paths[a][1]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data3 = int(str(paths[a][2]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data3 = str(paths[a][2]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data4 = int(str(paths[a][3]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data4 = str(paths[a][3]).replace('[', '').replace(']', '').replace("'", "")
            # print("4层" + str(paths[a]) + "====>" + str(data_json[data1][data2][data3][data4]))
            datavalue = str(data_json[data1][data2][data3][data4])
            datavalue1 = data_json[data1][data2][data3][data4]
            # print(type(datavalue1),datavalue1)
            newline = ''
            # print(type(datajson[data1][data2][data3][data4]),datajson[data1][data2][data3][data4])
            if type(datavalue1) == int or type(datavalue1) == float:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
            elif type(datavalue1) == str:
                newline = case1 + "" + c + " == \'" + datavalue + "\')"
                test_case.write('\n' + newline)
            elif datavalue1 == 'None':
                newline = case1 + "" + c + " == " + r"None" + ")"
                test_case.write('\n' + newline)
            elif type(datavalue1) == bool:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
            elif type(datavalue) == list:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
        if len(paths[a]) == 5:
            try:
                data1 = int(str(paths[a][0]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data1 = str(paths[a][0]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data2 = int(str(paths[a][1]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data2 = str(paths[a][1]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data3 = int(str(paths[a][2]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data3 = str(paths[a][2]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data4 = int(str(paths[a][3]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data4 = str(paths[a][3]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data5 = int(str(paths[a][4]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data5 = str(paths[a][4]).replace('[', '').replace(']', '').replace("'", "")
            # print("5层" + str(paths[a]) + "====>" + str(data_json[data1][data2][data3][data4][data5]))
            datavalue = str(data_json[data1][data2][data3][data4][data5])
            datavalue1 = datajson[data1][data2][data3][data4][data5]
            newline = ''
            if type(datavalue1) == int or type(datavalue1) == float:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
            elif type(datavalue1) == str:
                newline = case1 + "" + c + " == \'" + datavalue + "\')"
                test_case.write('\n' + newline)
            elif datavalue1 == 'None':
                newline = case1 + "" + c + " == " + r"None" + ")"
                test_case.write('\n' + newline)
            elif type(datavalue1) == bool:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
            elif type(datavalue) == list:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
        if len(paths[a]) == 6:
            try:
                data1 = int(str(paths[a][0]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data1 = str(paths[a][0]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data2 = int(str(paths[a][1]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data2 = str(paths[a][1]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data3 = int(str(paths[a][2]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data3 = str(paths[a][2]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data4 = int(str(paths[a][3]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data4 = str(paths[a][3]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data5 = int(str(paths[a][4]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data5 = str(paths[a][4]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data6 = int(str(paths[a][5]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data6 = str(paths[a][5]).replace('[', '').replace(']', '').replace("'", "")
            datavalue = str(data_json[data1][data2][data3][data4][data5][data6])
            datavalue1 = datajson[data1][data2][data3][data4][data5][data6]
            newline = ''
            if type(datavalue1) == int or type(datavalue1) == float:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
            elif type(datavalue1) == str:
                newline = case1 + "" + c + " == \'" + datavalue + "\')"
                test_case.write('\n' + newline)
            elif datavalue1 == 'None':
                newline = case1 + "" + c + " == " + r"None" + ")"
                test_case.write('\n' + newline)
            elif type(datavalue1) == bool:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
            elif type(datavalue) == list:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
            # print("6层" + str(paths[a]) + "====>" + str(data_json[data1][data2][data3][data4][data5][data6]))
        if len(paths[a]) == 7:
            try:
                data1 = int(str(paths[a][0]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data1 = str(paths[a][0]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data2 = int(str(paths[a][1]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data2 = str(paths[a][1]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data3 = int(str(paths[a][2]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data3 = str(paths[a][2]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data4 = int(str(paths[a][3]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data4 = str(paths[a][3]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data5 = int(str(paths[a][4]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data5 = str(paths[a][4]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data6 = int(str(paths[a][5]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data6 = str(paths[a][5]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data7 = int(str(paths[a][6]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data7 = str(paths[a][6]).replace('[', '').replace(']', '').replace("'", "")
            datavalue = str(data_json[data1][data2][data3][data4][data5][data6][data7])
            datavalue1 = datajson[data1][data2][data3][data4][data5][data6][data7]
            newline = ''
            if type(datavalue1) == int or type(datavalue1) == float:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
            elif type(datavalue1) == str:
                newline = case1 + "" + c + " == \'" + datavalue + "\')"
                test_case.write('\n' + newline)
            elif datavalue1 == 'None':
                newline = case1 + "" + c + " == " + r"None" + ")"
                test_case.write('\n' + newline)
            elif type(datavalue1) == bool:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
            elif type(datavalue) == list:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
        if len(paths[a]) == 8:
            try:
                data1 = int(str(paths[a][0]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data1 = str(paths[a][0]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data2 = int(str(paths[a][1]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data2 = str(paths[a][1]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data3 = int(str(paths[a][2]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data3 = str(paths[a][2]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data4 = int(str(paths[a][3]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data4 = str(paths[a][3]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data5 = int(str(paths[a][4]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data5 = str(paths[a][4]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data6 = int(str(paths[a][5]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data6 = str(paths[a][5]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data7 = int(str(paths[a][6]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data7 = str(paths[a][6]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data8 = int(str(paths[a][7]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data8 = str(paths[a][7]).replace('[', '').replace(']', '').replace("'", "")
            # print("8层" + str(paths[a]) + "====>" + str(data_json[data1][data2][data3][data4][data5][data6][data7][data8]))
            datavalue = str(data_json[data1][data2][data3][data4][data5][data6][data7][data8])
            datavalue1 = datajson[data1][data2][data3][data4][data5][data6][data7][data8]
            newline = ''
            if type(datavalue1) == int or type(datavalue1) == float:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
            elif type(datavalue1) == str:
                newline = case1 + "" + c + " == \'" + datavalue + "\')"
                test_case.write('\n' + newline)
            elif datavalue1 == 'None':
                newline = case1 + "" + c + " == " + r"None" + ")"
                test_case.write('\n' + newline)
            elif type(datavalue1) == bool:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
            elif type(datavalue) == list:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
        if len(paths[a]) == 9:
            try:
                data1 = int(str(paths[a][0]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data1 = str(paths[a][0]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data2 = int(str(paths[a][1]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data2 = str(paths[a][1]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data3 = int(str(paths[a][2]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data3 = str(paths[a][2]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data4 = int(str(paths[a][3]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data4 = str(paths[a][3]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data5 = int(str(paths[a][4]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data5 = str(paths[a][4]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data6 = int(str(paths[a][5]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data6 = str(paths[a][5]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data7 = int(str(paths[a][6]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data7 = str(paths[a][6]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data8 = int(str(paths[a][7]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data8 = str(paths[a][7]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data9 = int(str(paths[a][8]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data9 = str(paths[a][8]).replace('[', '').replace(']', '').replace("'", "")
            # print("9层" + str(paths[a]) + "====>" + str(data_json[data1][data2][data3][data4][data5][data6][data7][data8][data9]))
            datavalue = str(data_json[data1][data2][data3][data4][data5][data6][data7][data7][data8][data9])
            datavalue1 = datajson[data1][data2][data3][data4][data5][data6][data7][data8][data9]
            newline = ''
            if type(datavalue1) == int or type(datavalue1) == float:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
            elif type(datavalue1) == str:
                newline = case1 + "" + c + " == \'" + datavalue + "\')"
                test_case.write('\n' + newline)
            elif datavalue1 == 'None':
                newline = case1 + "" + c + " == " + r"None" + ")"
                test_case.write('\n' + newline)
            elif type(datavalue1) == bool:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
            elif type(datavalue) == list:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
        if len(paths[a]) == 10:
            try:
                data1 = int(str(paths[a][0]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data1 = str(paths[a][0]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data2 = int(str(paths[a][1]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data2 = str(paths[a][1]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data3 = int(str(paths[a][2]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data3 = str(paths[a][2]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data4 = int(str(paths[a][3]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data4 = str(paths[a][3]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data5 = int(str(paths[a][4]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data5 = str(paths[a][4]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data6 = int(str(paths[a][5]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data6 = str(paths[a][5]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data7 = int(str(paths[a][6]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data7 = str(paths[a][6]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data8 = int(str(paths[a][7]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data8 = str(paths[a][7]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data9 = int(str(paths[a][8]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data9 = str(paths[a][8]).replace('[', '').replace(']', '').replace("'", "")
            try:
                data10 = int(str(paths[a][9]).replace('[', '').replace(']', '').replace("'", ""))
            except ValueError as e:
                data10 = str(paths[a][9]).replace('[', '').replace(']', '').replace("'", "")
            # print("10层" + str(paths[a]) + "====>" + str(data_json[data1][data2][data3][data4][data5][data6][data7][data8][data9][data10]))
            datavalue = str(data_json[data1][data2][data3][data4][data5][data6][data7][data7][data8][data9][data10])
            datavalue1 = datajson[data1][data2][data3][data4][data5][data6][data7][data8][data9][data10]
            newline = ''
            if type(datavalue1) == int or type(datavalue1) == float:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
            elif type(datavalue1) == str:
                newline = case1 + "" + c + " == \'" + datavalue + "\')"
                test_case.write('\n' + newline)
            elif datavalue1 == 'None':
                newline = case1 + "" + c + " == " + r"None" + ")"
                test_case.write('\n' + newline)
            elif type(datavalue1) == bool:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
            elif type(datavalue) == list:
                newline = case1 + "" + c + " == " + datavalue + ")"
                test_case.write('\n' + newline)
    test_case.write('\n'+'\n')
    test_case.close()

